using System;
using NUnit.Framework;
using ValidationFramework.Configuration;
using ValidationFramework.Extensions;
using ValidationFramework.Reflection;

namespace ValidationFramework.Tests.Configuration
{
    [TestFixture]
    public class EnumerableDuplicateRuleConfigReaderTest
    {

        #region Methods

        [Test]
        public void ReadConfigSimple()
        {
            const string validatorXml = "<rule typeName='EnumerableDuplicateRule'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (EnumerableDuplicateRule)ConfigurationService.GetRule(ruleData, TypePointers.StringTypeHandle);
            Assert.AreEqual(null, rule.ErrorMessage);
            Assert.IsNull(rule.Comparer);

        }

        [Test]
        public void ReadConfigComplex()
        {
            const string validatorXml = "<rule errorMessage='hello' typeName='EnumerableDuplicateRule'  ruleSet='foo' equalityComparerTypeName='System.StringComparer' equalityComparerPropertyName='InvariantCulture'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
			var rule = (EnumerableDuplicateRule)ConfigurationService.GetRule(ruleData, TypePointers.StringTypeHandle);
            Assert.AreEqual("hello", rule.ErrorMessage);
            Assert.AreEqual(StringComparer.InvariantCulture, rule.Comparer);

        }

        #endregion


    }
}